import React from 'react';
import $ from 'jquery';
import './jquery.form';
import {Alert} from 'antd';

const base = "./data/";
import {hashHistory} from 'react-router';
import {message, Button} from 'antd';

let baseUrl = "http://10.5.1.102:8295/easywalk-admin/";//
const envs={
    "maoyt":"http://10.5.1.98:8088/",
    "xiongjj":"http://10.5.1.37:8080/easywalk-admin/",
    "prod":"https://hlx.cardpu.com:8208/easywalk-admin-merge/",
    "show":"http://whkayak.f3322.net:19030/easywalk-admin/",
    "liusong":"http://10.5.2.25:8080/easywalk-admin-merge/",
    "dev":"http://10.5.1.118:8395/easywalk-admin-merge/",
    "dev1":"https://demohlx.cardpu.com:8208/easywalk-admin-merge/",
    "hdl":"http://10.5.1.28:9013/",
}
https://demohlx.cardpu.com:8208
const mockPath="./mock/";
const envType="prod";
const util = {};
//util.baseUrl = baseUrl.split("/fapp-admin-wh/platform/")[0];
baseUrl = envs[envType];
util.upUrl = baseUrl;
util.getImgUrl = baseUrl + "platform/showimg.json?resource_id=";
util.getFileUrl = baseUrl + "platform/downloadfile?resource_id=";
util.getBase = function () {
    return base;
};

// 导出表报
util.exportRuquest = function (params,url){
    if (!params) {
        params = {};
    }
    var user = util.getLocalObj("userInfo");
    //params["head_jessionid"] = user.head_jessionid == undefined ? "" : user.head_jessionid.toString();
    //params["channel_id"] = user.channel_id == undefined ? '9' : user.channel_id;
    //params["ent_id"] = user.ent_id == undefined ? "" : user.ent_id.toString();
    //params["user_id"] = user.user_id == undefined ? "" : user.user_id.toString();

    var str = '';
    for (var key in params) {
        str += "&" + key + "=" + params[key];
    }
    str = str.substr(1);
    var hrefUrl = baseUrl+ url + '?' + str;
    console.info(hrefUrl);
    location.href = encodeURI(hrefUrl);
}

// 发送请求
util.httpRequest = function (params) {
    if (!params.params) {
        params.params = {};
    }
    var user = util.getLocalObj("userInfo");
    params.params["system_id"] = user.system_id == undefined ? 'easywalk' : user.system_id;
    params.params["channel_id"] = user.channel_id == undefined ? '9' : user.channel_id;
    //params.params["user_id"] = user.user_id == undefined ? "" : user.user_id.toString();
    //params.params["ent_id"] = user.ent_id == undefined ? "" : user.ent_id.toString();
    //params.params["email"] = user. email == undefined ? "" : user.email.toString();
    params.params["head_jessionid"] = user.head_jessionid == undefined ? "" : user.head_jessionid.toString();
    //params.params["head_jsessionid"] = user.head_jessionid == undefined ? "" : user.head_jessionid.toString();
    var url = '';
    var mockUrl=mockPath+params.url;
    if (params.plattype) {
        url += params.plattype + params.url;
    } else {
        url += '' + params.url;
    }

    url = baseUrl + url;
    var para = {
        type: envType=="mock"?"GET":params.type,
        data: params.params,
        url: envType=="mock"?mockUrl:url,
        dataType: "json",
        timeout: 10000,
        success: function (d) {
            console.log("response" + url);
            console.log(d);
            // 自动下线
            if (d.ret_code == "100101") {
                window.localStorage.removeItem("userInfo");
                window.localStorage.removeItem("sessionid");
                hashHistory.push("login");
            } else if (d.ret_code != "0000") {
                message.error(d.ret_msg);
                return;
            } else if (d.ret_code == "0000") {
                params.success(d);
            }
        },
        error: function (c) {
            console.log("error");
            if ($.isFunction(params.error)) {
                params.error(c);
            }
        },
        complete: function (c) {
            console.log("complete");
            if ($.isFunction(params.complete)) {
                params.complete(c);
            }
        }
    };
    console.log(para);
    console.log("开始请求ajax");
    $.ajax(para);
};
util.extend = (...args) => {
    return $.extend.apply(this, args);
};
util.isArray = (array) => {
    return $.isArray(array);
};
util.findKey = (array, key, value) => {
    if (!array)
        return null;
    var index = -1;
    array.forEach(function (item, i) {
        if (item[key] == value) {
            index = i;
            return false;
        }
    });
    return index;
};
util.findValue = (array, key, value, valueKey) => {
    const index = util.findKey(array, key, value);
    if (index != -1) {
        if (valueKey) {
            return array[index][valueKey];
        } else {
            return array[index];
        }
    }
    return "";
};
util.go = function (url, data) {
    if (data)
        url += "?" + $.param(data);
    window.location.href = url;
};
util.getRuleMenus = getRuleMenus;

function getRuleMenus(menus, rules) {
    function filter(menus) {
        $.each(menus, function (i, menu) {
            if ($.isArray(menu["children"])) {
                filter(menu["children"]);
                var children = [];
                $.each(menu["children"], function (j, menu) {
                    if (rules.indexOf(menu["id"]) != -1 || menu.hide === false) {
                        children.push(menu);
                        delete menu.hide;
                    }
                });
                menu["children"] = children;
                if (children.length > 0) {
                    menu["hide"] = false;
                } else {
                    delete menu["children"];
                }
            }
        })
    }

    filter(menus);
    var nmenus = [];
    $.each(menus, function (i, menu) {
        if (menu.hide === false) {
            nmenus.push(menu);
            delete menu.hide;
        }
    });
    return nmenus;
}

const map = {};
util.set = function (key, value) {
    map[key] = value;
};
util.get = function (key) {
    return map[key]
};

util.getDict = function (url, params) {
    var result;
    util.httpRequest({
        type: "GET", url: url, params: params, async: false, success: function (result) {
            for (var key in result) {
                result = result;
            }
        }
    });
    return result;
};

const rule = {};
util.getDict = function (key) {
    return dict[key];
};
util.hasRule = function (key) {
    return true;
    //return rule[key];
};
util.getSysDict = function (key) {
    if (!key) {
        return [];
    }
    var diclist = JSON.parse(localStorage.getItem("sys_dic"));
    var list = [];
    if (diclist) {
        for (var i = 0; i < diclist.length; i++) {
            if (diclist[i].dict == key) {
                list.push(diclist[i]);
            }
        }
        return list;
    }
    else {
        return [];
    }
}

util.convert = function (type, value) {
    if (!value) {
        return "";
    }
    
    var diclist = JSON.parse(localStorage.getItem("sys_dic"));
    if (diclist) {
        for (var i = 0; i < diclist.length; i++) {
            if (diclist[i].dict == type && diclist[i].itemkey == value) {
                return diclist[i].itemval;
            }
        }
    }
    return value;
};

util.stringtodate = function (str) {
    var year = str.substr(0, 4),
        month = str.substr(4, 2),
        date = str.substr(6, 2),
        hour = str.substr(8, 2),
        minute = str.substr(10, 2),
        sencond = str.substr(12, 2);
    return year + "-" + month + "-" + date + " " + hour + ":" + minute + ":" + sencond;
};
util.dateFormat = function (date, fmt) {
    if (date == null) {
        return "";
    }
    var o = {
        "M+": date.getMonth() + 1, //月份
        "d+": date.getDate(), //日
        "h+": date.getHours(), //小时
        "m+": date.getMinutes(), //分
        "s+": date.getSeconds(), //秒
        "q+": Math.floor((date.getMonth() + 3) / 3), //季度
        "S": date.getMilliseconds() //毫秒

    };
    if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (date.getFullYear() + "").substr(4 - RegExp.$1.length));
    for (var k in o)
        if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
    return fmt;
};

util.dateRender = function (value) {
    if (value) {
        return util.stringtodate(value);
    }
    return false;
};
util.dateTime = function (date, time, format) {

};
util.dictRender = function (dict) {
    const array = util.getDict(dict);
    return function (value) {
        const index = util.findKey(array, "value", value);
        if (index != -1) {
            return array[index].text;
        }
        return false;
    }
};
util.isString = function (str) {
    return Object.prototype.toString.call(str) === "[object String]";
};
util.valueToText = function (array, value) {

    if (util.isString(array))
        array = util.getDict(array);

    const index = util.findKey(array, "value", value);
    if (index != -1) {
        return array[index].text;
    }
    return "";
};

util.load = function (params, context) {
    const key = params.key,
        root = params.root || "rows";
    util.request({
        url: params.url,
        params: params.params
    }).success(function (data) {
        if (data["sys_retcode"] = "000000") {
            if (params.success) {
                params.success(data);
            } else {

                const obj = {};
                obj[key] = data[root];
                if (params.filter) {
                    params.filter(obj[key]);
                }
                context.setState(obj);
            }
        } else {
            console.log("数据加载失败");
        }
    });
};
util.isDefined = function (value) {
    return value === undefined;
};
util.submitFile = function (setting) {
    var form = $("<form>").attr({
        enctype: "multipart/form-data"
    }).append(setting.file);

    form.ajaxSubmit({
        url: util.getBase() + setting.url,
        type: "POST",
        data: setting.data,
        dataType: "json",
        success: function (data) {
            if (setting.success)
                setting.success(data);
        },
        error: function (data) {
            if (setting.error)
                setting.error(data);
        }
    });
};
util.sussess = function (data) {
    return data["sys_retcode"] == "000000";
};

util.setFields = function (fields, getFieldProps) {
    var fieldMap = {};

    fields.forEach(function (field) {
        if ($.isArray(field)) {
            field.forEach(function (item) {
                setProps(item, {});
            });
        } else {
            setProps(field.name, field);
        }
    });
    function setProps(name, setting) {
        setting.rules = [];
        if (setting.required) {
            setting.rules.push(setting)
        }

        if (setting.vtypes) {
            setting.vtypes.forEach(function (item) {
                var fn = util.vtype[item.name];
                if (fn) {
                    setting.rules.push({
                        validator: fn(item.msg)
                    })
                }
            });
        }
        fieldMap[name] = getFieldProps(name, setting)
    }
    return fieldMap;
};


util.params = function (data, array) {
    var pm = $.extend({}, data);
    if (array) {
        array.forEach(function (item) {
            var date = pm[item.name];
            if (date) {
                var format = item.format || "yyyyMMdd";
                if ($.isArray(date)) {
                    if (!item.keys) {
                        console.log("没有配置keys");
                    } else {
                        pm[item.keys[0]] = util.dateFormat(date[0], format);
                        pm[item.keys[1]] = util.dateFormat(date[1], format);
                    }
                } else {
                    pm[item.name] = util.dateFormat(date, format);
                }
            }
        })
    }
    return pm;
};


util.getRules = function () {
    var loginInfo = JSON.parse(sessionStorage.getItem("loginInfo"));

    if (loginInfo) {
        return loginInfo.rolenodes.map(function (node) {
            return node.sys_nodeid;
        })
    }
    return [];
};

util.splitArray = function (array, len) {
    var cloneArray = array.slice(0),
        newArray = [],
        arr = cloneArray.splice(0, len),
        push = function (arr) {
            if (arr.length > 0) {
                newArray.push(arr)
            }
        };
    push(arr);
    while (arr.length > 0) {
        arr = cloneArray.splice(0, len);
        push(arr);
    }
    return newArray;
};

util.upload = function (url, params) {
    url = util.getBase() + url;
    if (params)
        url += "?" + $.param(params);
    window.open(url);
};

util.vtype = {
    dateRange: function (msg) {
        return function (rule, value, callback) {
            if (!value[0]) {
                callback(new Error(msg));
            } else {
                callback();
            }
        }
    }
};
util.sum = function (rows, fields) {
    var data = {};

    rows.forEach(function (row) {
        fields.forEach(function (field) {
            if (data[field])
                data[field] = 0;
            data[field] += row[field]
        });
    });
    return data;
};

util.money = function (value) {
    var re = /(\d{1,3})(?=(\d{3})+(?:$|\.))/g;
    if (value) {
        return String(value).replace(re, "$1,");
    }
    return "";
};

util.interval = function () {
    let promise;
    return {
        start: function (fn, ms) {
            promise = setInterval(fn, ms);
        },
        cancel: function () {
            clearInterval(promise);
        }
    }
};

util.timeout = function () {
    let promise;
    return {
        start: function (fn, ms) {
            promise = setTimeout(fn, ms);
            timeoutList.push(promise);
        },
        cancel: function () {
            clearTimeout(promise);
        }
    }
};
//日期转字符串
util.date2str = function (date) {
    if (date && date.constructor == Date) {
        let m = date.getMonth() + 1, d = date.getDate();
        if (m < 10) {
            m = "0" + m;
        }
        if (d < 10) {
            d = "0" + d
        }
        return date.getFullYear() + "" + m + "" + d;
    } else {
        return "";
    }
};
//日期转字符串
util.str2formatstr = function (date, format) {
    if (!date) return;
    if (!format) format = "yyyy-MM-dd";
    switch (typeof date) {
        case "string":
            date = new Date(date.replace(/-/, "/"));
            break;
        case "number":
            date = new Date(date);
            break;
    }
    if (!date instanceof Date) return;
    var dict = {
        "yyyy": date.getFullYear(),
        "M": date.getMonth() + 1,
        "d": date.getDate(),
        "H": date.getHours(),
        "m": date.getMinutes(),
        "s": date.getSeconds(),
        "MM": ("" + (date.getMonth() + 101)).substr(1),
        "dd": ("" + (date.getDate() + 100)).substr(1),
        "HH": ("" + (date.getHours() + 100)).substr(1),
        "mm": ("" + (date.getMinutes() + 100)).substr(1),
        "ss": ("" + (date.getSeconds() + 100)).substr(1)
    };
    return format.replace(/(yyyy|MM?|dd?|HH?|ss?|mm?)/g, function () {
        return dict[arguments[0]];
    });
};
/**
 * 字符串转时间对象
 * @param str 需要被转字符串对象
 * @param format 字符串格式 eg. 'yyyyMMdd'
 * @returns {Date}
 */
util.str2date = function (str, format) {
    var date = new Date();

    if (!str) {
        throw '请设置时间字符串';
    }

    if (!format) {
        //throw '请设置时间字符串格式 如 yyyy年MM月dd日 HH:mm:ss';sdf
        format = "yyyyMMdd HH:mm:ss";
    }

    var unit = {
        yyyy: 'setFullYear',
        MM: 'setMonth',
        dd: 'setDate',
        HH: 'setHours',
        mm: 'setMinutes',
        ss: 'setSeconds',
        SSS: 'setMilliseconds'
    };
    for (var key in unit) {
        var startIndex = format.indexOf(key);
        var endIndex = format.indexOf(key) + key.length;
        if (startIndex < 0) continue;
        var value = str.substring(startIndex, endIndex);
        if (key === 'MM') --value;
        date[unit[key]](value);
    }
    return date;
};
/**
 * 时间相差多少天
 * @param sdate 开始时间
 * @param edate 结束时间
 * @returns {{difference}}
 */
util.dateDiff = function (sdate, edate) {
    if (sdate.constructor != Date) {
        throw 'arguments[0] is not Date Object!'
    }
    if (edate.constructor != Date) {
        throw 'arguments[1] is not Date Object!'
    }
    var DValue = edate.getTime() - sdate.getTime();
    var difference = {};
    difference.getDDate = function () {
        return parseInt(DValue / 1000 / 60 / 60 / 24, 10); //时间换算天sdf
    };
    difference.getDHours = function () {
        return parseInt(DValue / 1000 / 60 / 60 % 24, 10);//时间换算小时ssd23
    };
    difference.getDMinutes = function () {
        return parseInt(DValue / 1000 / 60 % 60, 10); // 时间换算分钟sdf234
    };
    difference.getDSeconds = function () {
        return parseInt(DValue / 1000 % 60, 10); //时间换算秒
    };
    difference.getDMilliseconds = function () {
        return parseInt(DValue % 1000, 10); // 时间换算毫秒scd
    };
    difference.print = function () {
        return '它们相差：' + this.getDDate() + '天' + this.getDHours() + '时' + this.getDMinutes() + '分' + this.getDSeconds() + '秒' + this.getDMilliseconds() + '毫秒';
    };
    return difference;
};
//时间字符串格式化 例如"20121212"转化为"2012-12-12"123
util.dateStrFormat = function (datestr, type) {
    var str = "";
    if (datestr == "" || datestr == null) {
        return "";
    }
    if (type == "D") {
        str = datestr.slice(0, 4) + "-" + datestr.slice(4, 6) + "-" + datestr.slice(6, 8);
    }
    else if (type == "T") {
        str = datestr.slice(0, 2) + ":" + datestr.slice(2, 4) + ":" + datestr.slice(4, 6);
    } else if (type == "DT") {
        str = datestr.slice(0, 4) + "-" + datestr.slice(4, 6) + "-" + datestr.slice(6, 8) + " " + datestr.slice(8, 10) + ":" + datestr.slice(10, 12) + ":" + datestr.slice(12, 14);
    }
    return str;
};

util.dateCount = function (date, num, unit) {//时间加减 nies
    if (typeof date == "string") {
        date = this.str2date(date, "yyyyMMddHHmmss");
    }
    switch (unit) {
        case "y":
            date.setFullYear(date.getFullYear() + num);
            break;
        case "M":
            date.setMonth(date.getMonth() + num);
            break;
        case "d":
            date.setDate(date.getDate() + num);
            break;
        case "h":
            date.setHours(date.getHours() + num);
            break;
        case "m":
            date.setMinutes(date.getMinutes() + num);
            break;
        case "s":
            date.setSeconds(date.getSeconds() + num);
            break;
        case "S":
            date.setMilliseconds(date.getMilliseconds() + num);
    }
    return date;
};

/**
 * 四舍五入
 * @param num 需要四舍五入的数字
 * @param precision 保留进度 默认保留2位小数
 * @returns {number}
 */
util.round = function (num, precision) {
    precision = precision ? precision : 2;
    num = Math.pow(10, precision) * num;
    num = Math.round(num);
    return num / Math.pow(10, precision);
};

//util.datetostr = function (date) {
//    let m = date.getMonth() + 1, d = date.getDayOfMonth();
//    if (m < 10) {
//        m = "0" + m;
//    }
//    if (d < 10) {
//        d = "0" + d
//    }
//    return date.getYear() + "" + m + "" + d;
//};
//
//util.jsdatetostr = function (date) {
//    let m = date.getMonth() + 1, d = date.getDate();
//    if (m < 10) {
//        m = "0" + m;
//    }
//    if (d < 10) {
//        d = "0" + d
//    }
//    return date.getYear() + "" + m + "" + d;
//};

util.setLocal = function (key, value) {
    window.localStorage.setItem(key, value);
};
util.getLocal = function (key, defaultValue) {
    return window.localStorage.getItem(key) || defaultValue || null;
};
util.setLocalObj = function (key, value) {
    window.localStorage.setItem(key, JSON.stringify(value));
};
util.getLocalObj = function (key) {
    return JSON.parse(window.localStorage.getItem(key) || "{}");
};
util.clone = function (myObj) {
    if (typeof(myObj) != 'object') return myObj;
    if (myObj == null) return myObj;
    var myNewObj = new Object();
    for (var i in myObj)
        myNewObj[i] = util.clone(myObj[i]);
    return myNewObj;
};
util.isArray = function (obj) {
    return $.isArray(obj);
};
util.filterArray = function (array) {
    for (var i = 0; i < array.length; i++) {
        if (array[i] == "" || typeof(array[i]) == "undefined") {
            array.splice(i, 1);
            i = i - 1;
        }
    }
    return array;
};

//  导出方法
util.exportExcel = function (url, params, targetId) {
    var fullurl = baseUrl + url;

    var submit2BlankAddHidden = function (form, key, val) {
        var hd = document.createElement('input');
        hd.type = 'hidden';
        hd.name = key;
        hd.value = (val === window.undefined ? '' : val);// encodeURIComponent
        form.appendChild(hd);
        return hd;
    };

    var form = document.createElement('form');
    form.target = targetId || '_blank';
    form.method = 'POST';
    form.action = fullurl;
    document.body.appendChild(form);

    // add dynamic params
    var hiddens = [];
    for (var key in params) {
        var ov = params[key];
        var type = typeof ov;
        if (type == 'undefined') {
        } else if (type != "function" && type != "object") {
            hiddens.push(submit2BlankAddHidden(form, key, ov));
        } else if (typeof ov == 'object' && ov.length != null) {
            if (ov.length) {
                for (var i = 0, len = ov.length; i < len; i++) {
                    hiddens.push(submit2BlankAddHidden(form, key, ov[i]));
                }
            }
        }
    }
    form.submit();

    if (hiddens) { // remove dynamic params
        for (var i = 0, len = hiddens.length; i < len; i++) {
            hiddens[i].remove();
        }
    }
    form.remove();
};

// 权限共同方法
util.checkRights = (nodeids) => {
    let oprates = util.getLocalObj("roleids");
    //let enableRights=new Array(nodeids.length).fill(false);
    // 12
    console.log("oprates:", oprates);
    let enableRights = [];
    for (let i = 0; i < nodeids.length; i++) {
        enableRights.push(false);
    }

    if (oprates.length == 0) {
        return enableRights;
    }
    if (oprates[0].toLowerCase() == "system") {
        // enableRights.fill(true);
        for (let i = 0; i < nodeids.length; i++) {
            enableRights[i] = true;
        }
    } else {
        for (let nodeid of oprates) {
            for (let [index, elem] of nodeids.entries()) {
                if (nodeid == elem) {
                    enableRights[index] = true;
                }
            }
        }
    }
    return enableRights;
};

var CryptoJS = CryptoJS || function (s, p) {
        var m = {}, l = m.lib = {}, n = function () {
            }, r = l.Base = {
                extend: function (b) {
                    n.prototype = this;
                    var h = new n;
                    b && h.mixIn(b);
                    h.hasOwnProperty("init") || (h.init = function () {
                        h.$super.init.apply(this, arguments)
                    });
                    h.init.prototype = h;
                    h.$super = this;
                    return h
                }, create: function () {
                    var b = this.extend();
                    b.init.apply(b, arguments);
                    return b
                }, init: function () {
                }, mixIn: function (b) {
                    for (var h in b)b.hasOwnProperty(h) && (this[h] = b[h]);
                    b.hasOwnProperty("toString") && (this.toString = b.toString)
                }, clone: function () {
                    return this.init.prototype.extend(this)
                }
            },
            q = l.WordArray = r.extend({
                init: function (b, h) {
                    b = this.words = b || [];
                    this.sigBytes = h != p ? h : 4 * b.length
                }, toString: function (b) {
                    return (b || t).stringify(this)
                }, concat: function (b) {
                    var h = this.words, a = b.words, j = this.sigBytes;
                    b = b.sigBytes;
                    this.clamp();
                    if (j % 4)for (var g = 0; g < b; g++)h[j + g >>> 2] |= (a[g >>> 2] >>> 24 - 8 * (g % 4) & 255) << 24 - 8 * ((j + g) % 4); else if (65535 < a.length)for (g = 0; g < b; g += 4)h[j + g >>> 2] = a[g >>> 2]; else h.push.apply(h, a);
                    this.sigBytes += b;
                    return this
                }, clamp: function () {
                    var b = this.words, h = this.sigBytes;
                    b[h >>> 2] &= 4294967295 <<
                        32 - 8 * (h % 4);
                    b.length = s.ceil(h / 4)
                }, clone: function () {
                    var b = r.clone.call(this);
                    b.words = this.words.slice(0);
                    return b
                }, random: function (b) {
                    for (var h = [], a = 0; a < b; a += 4)h.push(4294967296 * s.random() | 0);
                    return new q.init(h, b)
                }
            }), v = m.enc = {}, t = v.Hex = {
                stringify: function (b) {
                    var a = b.words;
                    b = b.sigBytes;
                    for (var g = [], j = 0; j < b; j++) {
                        var k = a[j >>> 2] >>> 24 - 8 * (j % 4) & 255;
                        g.push((k >>> 4).toString(16));
                        g.push((k & 15).toString(16))
                    }
                    return g.join("")
                }, parse: function (b) {
                    for (var a = b.length, g = [], j = 0; j < a; j += 2)g[j >>> 3] |= parseInt(b.substr(j,
                            2), 16) << 24 - 4 * (j % 8);
                    return new q.init(g, a / 2)
                }
            }, a = v.Latin1 = {
                stringify: function (b) {
                    var a = b.words;
                    b = b.sigBytes;
                    for (var g = [], j = 0; j < b; j++)g.push(String.fromCharCode(a[j >>> 2] >>> 24 - 8 * (j % 4) & 255));
                    return g.join("")
                }, parse: function (b) {
                    for (var a = b.length, g = [], j = 0; j < a; j++)g[j >>> 2] |= (b.charCodeAt(j) & 255) << 24 - 8 * (j % 4);
                    return new q.init(g, a)
                }
            }, u = v.Utf8 = {
                stringify: function (b) {
                    try {
                        return decodeURIComponent(escape(a.stringify(b)))
                    } catch (g) {
                        throw Error("Malformed UTF-8 data");
                    }
                }, parse: function (b) {
                    return a.parse(unescape(encodeURIComponent(b)))
                }
            },
            g = l.BufferedBlockAlgorithm = r.extend({
                reset: function () {
                    this._data = new q.init;
                    this._nDataBytes = 0
                }, _append: function (b) {
                    "string" == typeof b && (b = u.parse(b));
                    this._data.concat(b);
                    this._nDataBytes += b.sigBytes
                }, _process: function (b) {
                    var a = this._data, g = a.words, j = a.sigBytes, k = this.blockSize, m = j / (4 * k), m = b ? s.ceil(m) : s.max((m | 0) - this._minBufferSize, 0);
                    b = m * k;
                    j = s.min(4 * b, j);
                    if (b) {
                        for (var l = 0; l < b; l += k)this._doProcessBlock(g, l);
                        l = g.splice(0, b);
                        a.sigBytes -= j
                    }
                    return new q.init(l, j)
                }, clone: function () {
                    var b = r.clone.call(this);
                    b._data = this._data.clone();
                    return b
                }, _minBufferSize: 0
            });
        l.Hasher = g.extend({
            cfg: r.extend(), init: function (b) {
                this.cfg = this.cfg.extend(b);
                this.reset()
            }, reset: function () {
                g.reset.call(this);
                this._doReset()
            }, update: function (b) {
                this._append(b);
                this._process();
                return this
            }, finalize: function (b) {
                b && this._append(b);
                return this._doFinalize()
            }, blockSize: 16, _createHelper: function (b) {
                return function (a, g) {
                    return (new b.init(g)).finalize(a)
                }
            }, _createHmacHelper: function (b) {
                return function (a, g) {
                    return (new k.HMAC.init(b,
                        g)).finalize(a)
                }
            }
        });
        var k = m.algo = {};
        return m
    }(Math);
(function (s) {
    function p(a, k, b, h, l, j, m) {
        a = a + (k & b | ~k & h) + l + m;
        return (a << j | a >>> 32 - j) + k
    }

    function m(a, k, b, h, l, j, m) {
        a = a + (k & h | b & ~h) + l + m;
        return (a << j | a >>> 32 - j) + k
    }

    function l(a, k, b, h, l, j, m) {
        a = a + (k ^ b ^ h) + l + m;
        return (a << j | a >>> 32 - j) + k
    }

    function n(a, k, b, h, l, j, m) {
        a = a + (b ^ (k | ~h)) + l + m;
        return (a << j | a >>> 32 - j) + k
    }

    for (var r = CryptoJS, q = r.lib, v = q.WordArray, t = q.Hasher, q = r.algo, a = [], u = 0; 64 > u; u++)a[u] = 4294967296 * s.abs(s.sin(u + 1)) | 0;
    q = q.MD5 = t.extend({
        _doReset: function () {
            this._hash = new v.init([1732584193, 4023233417, 2562383102, 271733878])
        },
        _doProcessBlock: function (g, k) {
            for (var b = 0; 16 > b; b++) {
                var h = k + b, w = g[h];
                g[h] = (w << 8 | w >>> 24) & 16711935 | (w << 24 | w >>> 8) & 4278255360
            }
            var b = this._hash.words, h = g[k + 0], w = g[k + 1], j = g[k + 2], q = g[k + 3], r = g[k + 4], s = g[k + 5], t = g[k + 6], u = g[k + 7], v = g[k + 8], x = g[k + 9], y = g[k + 10], z = g[k + 11], A = g[k + 12], B = g[k + 13], C = g[k + 14], D = g[k + 15], c = b[0], d = b[1], e = b[2], f = b[3], c = p(c, d, e, f, h, 7, a[0]), f = p(f, c, d, e, w, 12, a[1]), e = p(e, f, c, d, j, 17, a[2]), d = p(d, e, f, c, q, 22, a[3]), c = p(c, d, e, f, r, 7, a[4]), f = p(f, c, d, e, s, 12, a[5]), e = p(e, f, c, d, t, 17, a[6]), d = p(d, e, f, c, u, 22, a[7]),
                c = p(c, d, e, f, v, 7, a[8]), f = p(f, c, d, e, x, 12, a[9]), e = p(e, f, c, d, y, 17, a[10]), d = p(d, e, f, c, z, 22, a[11]), c = p(c, d, e, f, A, 7, a[12]), f = p(f, c, d, e, B, 12, a[13]), e = p(e, f, c, d, C, 17, a[14]), d = p(d, e, f, c, D, 22, a[15]), c = m(c, d, e, f, w, 5, a[16]), f = m(f, c, d, e, t, 9, a[17]), e = m(e, f, c, d, z, 14, a[18]), d = m(d, e, f, c, h, 20, a[19]), c = m(c, d, e, f, s, 5, a[20]), f = m(f, c, d, e, y, 9, a[21]), e = m(e, f, c, d, D, 14, a[22]), d = m(d, e, f, c, r, 20, a[23]), c = m(c, d, e, f, x, 5, a[24]), f = m(f, c, d, e, C, 9, a[25]), e = m(e, f, c, d, q, 14, a[26]), d = m(d, e, f, c, v, 20, a[27]), c = m(c, d, e, f, B, 5, a[28]), f = m(f, c,
                d, e, j, 9, a[29]), e = m(e, f, c, d, u, 14, a[30]), d = m(d, e, f, c, A, 20, a[31]), c = l(c, d, e, f, s, 4, a[32]), f = l(f, c, d, e, v, 11, a[33]), e = l(e, f, c, d, z, 16, a[34]), d = l(d, e, f, c, C, 23, a[35]), c = l(c, d, e, f, w, 4, a[36]), f = l(f, c, d, e, r, 11, a[37]), e = l(e, f, c, d, u, 16, a[38]), d = l(d, e, f, c, y, 23, a[39]), c = l(c, d, e, f, B, 4, a[40]), f = l(f, c, d, e, h, 11, a[41]), e = l(e, f, c, d, q, 16, a[42]), d = l(d, e, f, c, t, 23, a[43]), c = l(c, d, e, f, x, 4, a[44]), f = l(f, c, d, e, A, 11, a[45]), e = l(e, f, c, d, D, 16, a[46]), d = l(d, e, f, c, j, 23, a[47]), c = n(c, d, e, f, h, 6, a[48]), f = n(f, c, d, e, u, 10, a[49]), e = n(e, f, c, d,
                C, 15, a[50]), d = n(d, e, f, c, s, 21, a[51]), c = n(c, d, e, f, A, 6, a[52]), f = n(f, c, d, e, q, 10, a[53]), e = n(e, f, c, d, y, 15, a[54]), d = n(d, e, f, c, w, 21, a[55]), c = n(c, d, e, f, v, 6, a[56]), f = n(f, c, d, e, D, 10, a[57]), e = n(e, f, c, d, t, 15, a[58]), d = n(d, e, f, c, B, 21, a[59]), c = n(c, d, e, f, r, 6, a[60]), f = n(f, c, d, e, z, 10, a[61]), e = n(e, f, c, d, j, 15, a[62]), d = n(d, e, f, c, x, 21, a[63]);
            b[0] = b[0] + c | 0;
            b[1] = b[1] + d | 0;
            b[2] = b[2] + e | 0;
            b[3] = b[3] + f | 0
        }, _doFinalize: function () {
            var a = this._data, k = a.words, b = 8 * this._nDataBytes, h = 8 * a.sigBytes;
            k[h >>> 5] |= 128 << 24 - h % 32;
            var l = s.floor(b /
                4294967296);
            k[(h + 64 >>> 9 << 4) + 15] = (l << 8 | l >>> 24) & 16711935 | (l << 24 | l >>> 8) & 4278255360;
            k[(h + 64 >>> 9 << 4) + 14] = (b << 8 | b >>> 24) & 16711935 | (b << 24 | b >>> 8) & 4278255360;
            a.sigBytes = 4 * (k.length + 1);
            this._process();
            a = this._hash;
            k = a.words;
            for (b = 0; 4 > b; b++)h = k[b], k[b] = (h << 8 | h >>> 24) & 16711935 | (h << 24 | h >>> 8) & 4278255360;
            return a
        }, clone: function () {
            var a = t.clone.call(this);
            a._hash = this._hash.clone();
            return a
        }
    });
    r.MD5 = t._createHelper(q);
    r.HmacMD5 = t._createHmacHelper(q)
})(Math);


util.md5String = function (n) {

    return CryptoJS.MD5(n).toString();
};

//表单校验纯数字方法
util.checkNumber = function (rule, value, callback) {
    //const { validateFields } = this.props.form;
    const reg = new RegExp("^[0-9]*$");
    if (value && !reg.test(value)) {
        callback([new Error('请输入纯数字')]);
    } else {
        callback();
    }
};
//数字放大一百倍并加百分号并去掉小数点两位以后
util.addPercent = function (value) {
    if (value != null) {
        return ((value * 100).toFixed(2) + "%");
    } else {
        return "";
    }
};
//菜单选项只能选四项123
util.checkUseType = function (rule, value, callback) {
    if (value.length != 4) {
        callback([new Error('只能选择四项')]);
    } else {
        callback();
    }
};
//导航栏权限控制
util.menuControl = function (menu) {
    let roleids = util.getLocalObj("roleids");
    if (roleids.length == 0) {
        return [];
    }
    if (roleids[0].toLowerCase() == "system") {
        return menu;
    } else {
        let newMenu = [];
        for (let i = 0; i < roleids.length; i++) {
            for (let j = 0; j < menu.length; j++) {
                if (menu[j].id == roleids[i]) {
                    newMenu.push(roleids[i]);
                }
                if (menu[j].children) {
                    for (let k = 0; k < menu[j].children.length; k++) {
                        if (menu[j].children[k].id == roleids[i]) {
                            newMenu.push(roleids[i]);
                        }
                        if (menu[j].children[k].children) {
                            for (let l = 0; l < menu[j].children[k].children.length; l++) {
                                if (roleids[i] == menu[j].children[k].children[l].id) {
                                    newMenu.push(roleids[i]);
                                }
                            }
                        }
                    }
                }
            }
        }
        console.log(newMenu);
        return newMenu;
    }
};
//数组去重
util.unique = function (arr) {
    var res = [];
    var json = {};
    for (var i = 0; i < arr.length; i++) {
        if (!json[arr[i]]) {
            res.push(arr[i]);
            json[arr[i]] = 1;
        }
    }
    return res;
};
//控制时间控件分选项只显示0分
util.range=function() {
    const result = [];
    for (let i = 1; i < 60; i++) {
        result.push(i);
    }
    return result;
};
export default util;

